export default {
    data() {
        return {
        }
    },
    computed: {
        basin() {
            return this.$store.getters.basin
        },
        basinArry() {
            return this.$store.getters.basinArry
        },
    },
    created() {
        this.$eventBus.$on('goHome', this.goHome)
    },
    watch: {
        basin: {
            handler: function (name) {
                this.$nextTick(() => {
                    this.setCameraPosByName(name)
                })
            },
            immediate: true
        }
    },
    methods: {
        goHome() {
            var pos = this.basinArry[this.basin]
            this.setCameraPos(pos.lon, pos.lat, pos.h, pos.r)
        },
        setCameraPosByName(name) {
            var pos = this.basinArry[name]
            this.setCameraPos(pos.lon, pos.lat, pos.h, pos.r)
        },
        setCameraPos(lon, lat, h, r) {
            this.$viewer.camera.setView({
                destination: Cesium.Cartesian3.fromDegrees(lon, lat, h),
                orientation: {
                    heading: Cesium.Math.toRadians(0.0), // east, default value is 0.0 (north)
                    pitch: Cesium.Math.toRadians(-90), // default value (looking down)
                    roll: r // default value
                }
            })
        }
    }
}
